package br.com.bean;

import java.util.List;

import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;

import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.ViewAccessScoped;

import br.com.domain.Domain;
import br.com.domain.Sexo;
import br.com.exception.BeanException;
import br.com.exception.ServiceException;
import br.com.filter.SexoFilter;
import br.com.service.GenericServiceImpl;
import br.com.service.SexoService;
import br.com.util.DomainListDataModel;

@Named
@ViewAccessScoped
public class SexoBean extends GenericBean{
	
	private static final long serialVersionUID = 1L;
	
	/**************************************************************************/
	/**                                ATRIBUTOS                             **/
	/**************************************************************************/
	
	@Inject /** Service **/	 
	private SexoService sexoService; 
	
	/** Objeto Principal do Bean **/
	private Sexo sexo = new Sexo();	
	
	/** Lista Principal do Bean **/
	private DomainListDataModel listSexo;
	
	/** Lista Principal do Bean **/
	private List<Sexo> listSexoSelecionados;
	
	/** Objeto de Filtro do Bean **/
	private SexoFilter sexoFilter = new SexoFilter();	  
	
	/**************************************************************************/
	/**                                M�TODOS                               **/
	/**************************************************************************/
	
	/**
	 * ON LOAD PAGE 
	 * @return void
	 */
	public void loadPage() {
	}
	
	/**
	 * NOVO REGISTRO
	 * @return void
	 */
	public void novo()  {
		this.activeModoNovo();
		this.sexo = new Sexo();
		this.goPage("pageSexoCad");
	}
	
	/**
	 * SALVAR REGISTRO
	 * @return void
	 */
	public void salvar()  {	
        try {
			this.salvar(this.sexo);
			this.goPage("pageSexoList");
		} catch (BeanException e) {
			MessageBean.showAlertMessage(e.getMessage());
		}
	}
	
	/**
	 * EDITAR REGISTRO
	 * @return void
	 */
	public void editar() {
		try {
			this.editar(this.sexo);
			this.goPage("pageSexoCad");
		} catch (BeanException e) {
			MessageBean.showAlertMessage(e.getMessage());
		}
	}
	
	/**
	 * EXCLUIR REGISTROS SELECIONADOS
	 * @return void
	 */
	public void excluir()  {
		try {
			this.excluir(this.listSexoSelecionados);
		} catch (ServiceException e) {
			MessageBean.showErrorMessage(e.getMessage() );
		}
	}
	
	/**
	 * VISUALIZAR REGISTRO
	 * @return void
	 */
	public void visualizar()  {
		super.activeModoVisualizar();
		this.goPage("pageSexoCad");
	}
	
	/**
	 * BUSCAR TODOS OS REGISTROS
	 * @return DomainListDataModel
	 */
	public DomainListDataModel buscarTodos()  {
		try {
			 this.listSexo = this.buscarTodos(Sexo.class);
		} catch (BeanException e) {
			MessageBean.showErrorMessage(e.getMessage());
		}
		return this.listSexo;
	}
	
	/**
	 * BUSCAR DADOS POR FILTRO
	 * @return void
	 */
	public void buscarPorFiltro()  {
		try {
			this.listSexo = buscarPorFiltro(this.sexoFilter);
		} catch (BeanException e) {
			MessageBean.showErrorMessage(e.getMessage());
		}
	}
	
	/**
	 * SAIR
	 * @return void
	 */
	public void sair() {
	   this.goPage("pageSexoList");
	}
	
	/**************************************************************************/
	/**                      M�TODOS  COMPLEMENTEARES                        **/
	/**************************************************************************/
	
	 @PostConstruct	 
	 public void initBean() throws ServiceException{
	    this.buscarTodos();
	 }
		
	/**************************************************************************/
	/**                           GET's E SET's                              **/
	/**************************************************************************/
	 @Override
	 public void setGenericService(GenericServiceImpl genericService) {
		super.setGenericService(this.sexoService);
	 }
	 
	 @Override
	 public GenericServiceImpl getGenericService() {
		return this.sexoService;
	 }
	 
	 @Override
	 public DomainListDataModel getListDomain() {
		 return this.getListSexo();
	 }

	 @Override
	 public List<? extends Domain> getListDomainSelecionados() {
		return this.listSexoSelecionados;
	 }
	 
	 @Override
	 public void setListDomainSelecionados(
			 List<? extends Domain> listDomainSelecionados) {
		 this.listSexoSelecionados = null;
	 }

	 @Override
	 public Boolean getIsButtonDeleteDisabled() {		
		 return this.desabilitarExclusao(this.listSexo, this.listSexoSelecionados);
	 }

	@Override
	public Domain getDomain() {
		return this.sexo;
	}
	 
	 public Sexo getSexo() {
		 return sexo;
	 }

	 public void setSexo(Sexo sexo) {
		 this.sexo = sexo;
	 }

	 public SexoFilter getSexoFilter() {
		 return sexoFilter;
	 }

	 public void setSexoFilter(SexoFilter sexoFilter) {
		 this.sexoFilter = sexoFilter;
	 }

	 public DomainListDataModel getListSexo() {
		 return listSexo;
	 }

	 public void setListSexo(DomainListDataModel listSexo) {
		 this.listSexo = listSexo;
	 }

	 public List<Sexo> getListSexoSelecionados() {
		 return listSexoSelecionados;
	 }

	 public void setListSexoSelecionados(List<Sexo> listSexoSelecionados) {
		 this.listSexoSelecionados = listSexoSelecionados;
	 }

}
